package pers.amos.edu.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import pers.amos.edu.common.GlobalResult;
import pers.amos.edu.pojo.CollectionMajor;
import pers.amos.edu.service.CollectionMajorService;

import java.util.List;

/**
 * @author amos wong
 * @create 2020-02-02 18:19
 */

@RestController
@RequestMapping("/edu/collection")
@Api(tags = "收藏专业的接口")
/**
 * 收藏专业接口
 */
public class CollectionMajorController {

    @Autowired
    private CollectionMajorService majorService;

    /**
     * 收藏专业的接口
     *
     * @param openId    微信用户的openId
     * @param schoolId  专业所属的学校id
     * @param majorName 专业名称
     * @return
     */
    @ApiOperation("用户收藏专业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "openId", value = "openId"),
            @ApiImplicitParam(name = "schoolId", value = "专业所属学校的id"),
            @ApiImplicitParam(name = "majorName", value = "专业的名称")})
    @PostMapping("/major/{openId}")
    public GlobalResult addCollection(@PathVariable String openId, Integer schoolId, String majorName) {
        return majorService.addCollection(openId, schoolId, majorName);
    }

    /**
     * 取消收藏专业的接口
     *
     * @param openId    微信用户的openId
     * @param schoolId  专业所属的学校id
     * @param majorName 专业名称
     * @return
     */
    @ApiOperation("用户取消收藏专业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "openId", value = "openId"),
            @ApiImplicitParam(name = "schoolId", value = "专业所属学校的id"),
            @ApiImplicitParam(name = "majorName", value = "专业的名称")})
    @DeleteMapping("/major/{openId}")
    public GlobalResult deleteCollection(@PathVariable String openId, Integer schoolId, String majorName) {
        return majorService.cancelCollection(openId, schoolId, majorName);
    }

    /**
     * 分页用户所收藏的专业
     *
     * @param openId 微信用户的openId
     * @return
     */
    @ApiOperation("查询某用户收藏专业")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "openId", value = "openId")
    )
    @GetMapping("/major/{openId}")
    public ResponseEntity<List<CollectionMajor>> getCollectionByPage(@PathVariable String openId) {
        List<CollectionMajor> list = majorService.getSchoolCollection(openId);
        return ResponseEntity.ok().body(list);
    }
}